<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            border-left: solid 1px #ddd;
            border-top: solid 1px #ddd;
            width: 800px;
            margin: auto;
        }

        td {
            border-right: solid 1px #ddd;
            border-bottom: solid 1px #ddd;
            height: 40px;
        }

        /* tr:nth-child(2n){
            background-color: #eee;
        } */
    </style>
</head>

<body>
    <table cellspacing="0" cellpadding="0">
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <div>
        <button onclick="showXXX()">获取ID为XXX的元素</button>
        <button onclick="showTagXXX()">获取标签为XXX的元素</button>
    </div>
    <script>
        // 获取网页中所有的行
        var trs = document.getElementsByTagName('tr');
        for (var i = 0; i < trs.length; i++) {
            if (i % 2 == 1) {
                var tr = trs[i]; // 获取到对应的行
                tr.style.background = '#eee';
            }
        }
        function showXXX(){
            var xxx = document.getElementById('xxx');
            console.log(xxx);
        }
        function showTagXXX(){
            var xxx = document.getElementsByTagName('xxx');
            console.log(xxx);
        }
    </script>
</body>

</html>